OPC Studio User's Guide and Reference
Examples - User Interface - OPC UA host and endpoint dialog
View with Navigation Tools

.NET

// This example shows how to let the user browse for a host (computer) and an endpoint of an OPC-UA server residing on it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System.Windows.Forms;
using OpcLabs.EasyOpc.UA.Forms.Browsing;

namespace UAFormsDocExamples._UAHostAndEndpointDialog
{
    static class ShowDialog
    {
        public static void Main1(IWin32Window owner)
        {
            var hostAndEndpointDialog = new UAHostAndEndpointDialog
            {
                EndpointDescriptor = {Host = "opcua.demo-this.com"}
            };

            DialogResult dialogResult = hostAndEndpointDialog.ShowDialog(owner);
            if (dialogResult != DialogResult.OK)
                return;

            // Display results
            MessageBox.Show(owner, 
                $"HostElement: {hostAndEndpointDialog.HostElement}\r\n" +
                $"DiscoveryElement: {hostAndEndpointDialog.DiscoveryElement}");
        }
    }
}

COM

// This example shows how to let the user browse for a host (computer) and an endpoint of an OPC-UA server residing on it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include "ShowDialog.h"

namespace _UAHostAndEndpointDialog
{
    void ShowDialog::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // 
            _UAHostAndEndpointDialogPtr HostAndEndpointDialogPtr(__uuidof(UAHostAndEndpointDialog));

            //
            HostAndEndpointDialogPtr->EndpointDescriptor->Host = L"opcua.demo-this.com";

            // 
            DialogResult dialogResult = HostAndEndpointDialogPtr->ShowDialog(NULL);
            _tprintf(_T("%d\n"), dialogResult);

            if (dialogResult == 1/*OK*/)
            {
                // Display results
                _HostElementPtr hostElementPtr = HostAndEndpointDialogPtr->HostElement;
                _tprintf(_T("HostElement: %s\n"), (hostElementPtr == NULL) ? _T("") : (LPCTSTR)CW2CT(hostElementPtr->ToString));
                _UADiscoveryElementPtr discoveryElementPtr = HostAndEndpointDialogPtr->DiscoveryElement;
                _tprintf(_T("DiscoveryElement: %s\n"), (discoveryElementPtr == NULL) ? _T("") : (LPCTSTR)CW2CT(discoveryElementPtr->ToString));
            }
        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}

Python

# This example shows how to let the user browse for a host (computer) and an endpoint of an OPC-UA server residing on it.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from System.Windows.Forms import *
from OpcLabs.EasyOpc.UA.Forms.Browsing import *


hostAndEndpointDialog = UAHostAndEndpointDialog()
hostAndEndpointDialog.EndpointDescriptor.Host = 'opcua.demo-this.com'

dialogResult = hostAndEndpointDialog.ShowDialog()
print(dialogResult)
if dialogResult != DialogResult.OK:
    exit()

# Display results.
print('HostElement: ', hostAndEndpointDialog.HostElement, sep='')
print('DiscoveryElement: ', hostAndEndpointDialog.DiscoveryElement, sep='')

print('Finished.')

 

See Also

Concepts